<?php


namespace app\common\controller;


use app\BaseController;
use app\common\constants\ReturnCodeConstants;
use app\common\util\Response;
use think\App;
use think\exception\HttpResponseException;


/**
 * Class AdminController
 * @package app\common\controller
 */
class ApiController extends BaseController
{
    protected $isValidate = true;

    public function __construct(App $app)
    {
        parent::__construct($app);

        if ($this->isValidate === true) {
            //验证器类
            $validateClassName = '\app\validate\\' . $this->request->controller();
            $validate = new $validateClassName;
            //对应方法名验证场景
            if (!$validate->scene($this->request->action())->check($this->request->param())) {
                $response = Response::failureJson(ReturnCodeConstants::C_P_ERROR, $validate->getError());
                throw new HttpResponseException($response);
            }
        }
    }

}